<template>
	<view class="wrap">
		<view class="top">
			<u-dropdown ref="dout" v-if="tt">
				<u-dropdown-item :title="shuname == ''?'选择诉求分类':shuname">
					<view style="width: 100%;height: 60vh;background-color: #fff;">
						<view class="item-container">
							<view class="thumb-box" v-for="(item1, index1) in quan" :key="index1"
								@click="dianji(item1.id,item1.name)">
								<image class="item-menu-image" :src="base+item1.imgUrl" mode=""></image>
								<view class="item-menu-name">{{item1.name}}</view>
							</view>
						</view>
					</view>
				</u-dropdown-item>
			</u-dropdown>
			<view class="item">
				<view class="left">标题</view>
				<input type="text" v-model="title" placeholder-class="line" placeholder="请填写" />
			</view>
			<view class="item">
				<view class="left">承办单位</view>
				<input type="text" v-model="ban" placeholder-class="line" placeholder="请填写" />
			</view>
			<view class="item">
				<view class="left">反馈手机</view>
				<input type="text" v-model="phone" placeholder-class="line" placeholder="请填写" />
			</view>
			<view class="item address">
				<view class="left">诉求内容</view>
				<textarea type="text" v-model="content" placeholder-class="line" placeholder="请填写" />
			</view>
			<uni-group title="上传图片">
				<uni-file-picker @select="select" :auto-upload="false" file-mediatype="image"></uni-file-picker>
			</uni-group>
		</view>
		<uni-group style="position: fixed;bottom: 0%;right: 0%;left: 0%;z-index: 99;">
			<button type="primary" @click="xia">发布诉求</button>
		</uni-group>

	</view>
</template>

<script>
	import api from 'commer/apiURL.js'
	export default {
		data() {
			return {
				base: api.baseurl,
				show: false,
				shuid: '',
				title: '',
				ban: '',
				phone: '',
				content: '',
				quan: [],
				shuname: '',
				tt: true,
				img: '',
			};
		},
		onLoad(options) {
			if(options.id != null){
				this.tt = false
				this.shuid = options.id
			}else{}
			this.getlun2()
		},
		methods: {
			select(e) {
				console.log(e.tempFilePaths[0])
				this.shang(e.tempFilePaths[0])
			},
			shang(e) {
				let token = uni.getStorageSync('token')
				uni.uploadFile({
					url: this.base + '/prod-api/common/upload',
					filePath: e,
					header: {
						'authorization': token
					},
					name: 'file',
					success: (res) => {
						let date = JSON.parse(res.data)
						this.img = '/prod-api' + date.fileName
					}
				})
			},
			xia() {
				if(this.shuid == ''|this.title == ''|this.content == ''|this.ban == ''){
					uni.showToast({
						title:'内容不能为空',
						icon:'none'
					})
					return
				}
				this.$post(this.base + '/prod-api/api/gov-service-hotline/appeal', {
					"appealCategoryId": this.shuid,
					"title": this.title,
					"content": this.content,
					"undertaker": this.ban,
					"imgUrl": this.img
				}).then((res) => {
					if (res.code == 200) {
						uni.showToast({
							title: '发布成功'
						})
						setTimeout(()=>{
							uni.navigateBack({
								
							})
						},500)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			getlun2() {
				this.$get(this.base + '/prod-api/api/gov-service-hotline/appeal-category/list').then((res) => {
					this.quan = res.rows
				})
			},
			dianji(id, name) {
				this.shuid = id
				this.shuname = name
				this.$refs.dout.close()
			},
			setDefault() {},
			showRegionPicker() {
				this.show = true;
			}
		}
	};
</script>

<style lang="scss" scoped>
	/deep/ .line {
		color: $u-light-color;
		font-size: 28rpx;
	}

	.wrap {
		background-color: #f2f2f2;

		.top {
			background-color: #ffffff;
			border-top: solid 2rpx $u-border-color;
			padding: 22rpx;

			.item {
				display: flex;
				font-size: 32rpx;
				line-height: 100rpx;
				align-items: center;
				border-bottom: solid 2rpx $u-border-color;

				.left {
					width: 180rpx;
				}

				input {
					text-align: left;
				}
			}

			.address {
				padding: 20rpx 0;

				textarea {
					// width: 100%;
					height: 150rpx;
					background-color: #f7f7f7;
					line-height: 60rpx;
					margin: 40rpx auto;
					padding: 20rpx;
				}
			}

			.site-clipboard {
				padding-right: 40rpx;

				textarea {
					// width: 100%;
					height: 150rpx;
					background-color: #f7f7f7;
					line-height: 60rpx;
					margin: 40rpx auto;
					padding: 20rpx;
				}

				.clipboard {
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 26rpx;
					color: $u-tips-color;
					height: 80rpx;

					.icon {
						margin-top: 6rpx;
						margin-left: 10rpx;
					}
				}
			}
		}

		.bottom {
			margin-top: 20rpx;
			padding: 40rpx;
			padding-right: 0;
			background-color: #ffffff;
			font-size: 28rpx;

			.tag {
				display: flex;

				.left {
					width: 160rpx;
				}

				.right {
					display: flex;
					flex-wrap: wrap;

					.tags {
						width: 140rpx;
						padding: 16rpx 8rpx;
						border: solid 2rpx $u-border-color;
						text-align: center;
						border-radius: 50rpx;
						margin: 0 10rpx 20rpx;
						display: flex;
						font-size: 28rpx;
						align-items: center;
						justify-content: center;
						color: $u-content-color;
						line-height: 1;
					}

					.plus {
						//padding: 10rpx 0;
					}
				}
			}

			.default {
				margin-top: 50rpx;
				display: flex;
				justify-content: space-between;
				border-bottom: solid 2rpx $u-border-color;
				line-height: 64rpx;

				.tips {
					font-size: 24rpx;
				}

				.right {}
			}
		}
	}

	.item-container {
		display: flex;
		flex-wrap: wrap;
	}

	.thumb-box {
		width: 25%;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		margin-top: 20rpx;
	}

	.item-menu-image {
		width: 60rpx;
		height: 60rpx;
	}
</style>
